home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / IBM VisualAge for Java Enterprise v4.0 Retail / ivj40 / setup / IDE.Cab / F77285_TextViewer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-04-25  |  5.0 KB  |  126 lines

  1. package com.ibm.ivb.jface.plus;
  2.  
  3. import com.ibm.ivb.jface.NullEvent;
  4. import com.ibm.ivb.jface.Tool;
  5. import com.ibm.ivf.ui.browser.interfaces.IElement;
  6. import com.ibm.ivf.ui.browser.interfaces.IProperty;
  7. import com.ibm.ivf.ui.browser.interfaces.SetPropertyVetoException;
  8. import com.ibm.ivf.ui.browser.model.SimpleProperty;
  9. import java.awt.Component;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JScrollPane;
  12. import javax.swing.JTextPane;
  13. import javax.swing.text.DefaultStyledDocument;
  14. import javax.swing.text.StyleContext;
  15. import javax.swing.text.StyledDocument;
  16.  
  17. public class TextViewer extends ToolViewer {
  18.    private static final String fgIBMCopyright = "(c) Copyright IBM Corporation 1998";
  19.    protected JScrollPane scrollPane;
  20.    protected JTextPane textPane = this.createTextPane();
  21.    protected StyleContext styleContext = this.createStyleContext();
  22.    protected StyledDocument document = this.createStyledDocument();
  23.    private boolean modified = false;
  24.    // $FF: renamed from: dh com.ibm.ivb.jface.plus.TextViewer.DocumentHandler
  25.    private DocumentHandler field_0 = new DocumentHandler(this);
  26.  
  27.    public TextViewer() {
  28.       JTextPane var10000 = this.textPane;
  29.       this.getClass();
  30.       ((Component)var10000).addMouseListener(new ToolViewer.PopupListener(this));
  31.       this.textPane.addCaretListener(this.field_0);
  32.    }
  33.  
  34.    protected StyleContext createStyleContext() {
  35.       return new StyleContext();
  36.    }
  37.  
  38.    protected StyledDocument createStyledDocument() {
  39.       return new DefaultStyledDocument(this.styleContext);
  40.    }
  41.  
  42.    protected JTextPane createTextPane() {
  43.       return new JTextPane(this.document);
  44.    }
  45.  
  46.    public void domainChanged(IElement var1, String var2, IElement var3) {
  47.       if (var1 != null && (var3 == null || var3 != ((ToolViewer)this).getCurrentElement())) {
  48.          if (var1 != ((ToolViewer)this).getCurrentElement() || var2 != null && !var2.equals(((ToolViewer)this).getCurrentPropertyName())) {
  49.             if (var1 != null && var3 == null && (var2.equals("name") || var2.equals("icon")) && var1 == ((ToolViewer)this).getCurrentElement()) {
  50.                ((Tool)this).setTitleIcon(var1.getIcon());
  51.                ((Tool)this).setTitle(var1.getName());
  52.             }
  53.  
  54.          } else {
  55.             this.textPane.setText(((ToolViewer)this).getCurrentProperty().toString());
  56.             this.textPane.repaint();
  57.          }
  58.       } else {
  59.          ((ToolViewer)this).updateInput(((ToolViewer)this).getCurrentElement());
  60.       }
  61.    }
  62.  
  63.    public Component getPrintableView() {
  64.       return this.textPane;
  65.    }
  66.  
  67.    protected String getSavePromptMessage() {
  68.       return ((ToolViewer)this).getCurrentElement().getName() + " " + ((ToolViewer)this).getCurrentProperty().toString() + " modified. Do you want to save?";
  69.    }
  70.  
  71.    public Component getView() {
  72.       return ((ToolViewer)this).createScrollPane(this.textPane);
  73.    }
  74.  
  75.    public void inputChanged(IElement var1, IProperty var2) {
  76.       if (this.isModified()) {
  77.          this.promptDocumentSave();
  78.       }
  79.  
  80.       this.textPane.getDocument().removeDocumentListener(this.field_0);
  81.       if (var1 != null && var2 != null) {
  82.          this.textPane.setText(var2.toString());
  83.          this.textPane.getDocument().addDocumentListener(this.field_0);
  84.       } else {
  85.          ((Tool)this).fireLinkEvent(new NullEvent(this));
  86.          this.textPane.setText("");
  87.       }
  88.  
  89.       this.textPane.repaint();
  90.    }
  91.  
  92.    public boolean isModified() {
  93.       return this.modified;
  94.    }
  95.  
  96.    protected void promptDocumentSave() {
  97.       int var1 = JOptionPane.showConfirmDialog(this.getView(), this.getSavePromptMessage(), "", 0);
  98.       if (var1 == 0) {
  99.          this.save();
  100.       }
  101.  
  102.    }
  103.  
  104.    public void save() {
  105.       IElement var1 = ((ToolViewer)this).getCurrentElement();
  106.       String var2 = ((ToolViewer)this).getCurrentPropertyName();
  107.       if (var1 != null && var2 != null) {
  108.          try {
  109.             var1.setProperty(var2, new SimpleProperty(this.textPane.getText()));
  110.             this.modified = false;
  111.          } catch (SetPropertyVetoException var3) {
  112.          }
  113.       }
  114.    }
  115.  
  116.    // $FF: synthetic method
  117.    static boolean access$0(TextViewer var0) {
  118.       return var0.modified;
  119.    }
  120.  
  121.    // $FF: synthetic method
  122.    static void access$1(TextViewer var0, boolean var1) {
  123.       var0.modified = var1;
  124.    }
  125. }
  126.